import React from "react";
import {observable, action} from "mobx";
import {Toast} from "antd-mobile";

import sqlite from "../db/sqlite";

class User {
	@observable userinfo = {
		userId: "",
		userName: "",
		userPhone: "",
		userPassword: "",
	}
	@observable list = {
		isFetching: true,
	}
	//账户资产明细；
	@observable assetList = {
		title: "可使用收支明细",
		tableTitle: ["姓名", "收入支出渠道", "数量", "时间"],
		tableBody: [{name: "liujing", qudao: "邀请好友赠送", shuliang: 6.0, time: "2017-09-03"}],
	}
	
	//用户注册;
	@action  setRegister() {
		const { userId, userName, userPhone, userPassword } = this.userinfo;
		sqlite.createUserTable();
		sqlite.saveUserInfo(userId, userName, userPhone, userPassword);

	}
	//用户登录；
	@action async getLogin(userPhone, userPwd) {
		sqlite.createUserTable();
		const ret = await sqlite.selectUserInfo(userPhone, userPwd);
		if(ret == "failed") {
			Toast.info("账号或密码错误");
			this.list.isFetching = false;
			console.log(this.list.isFetching)
		}else if(ret == "successed") {
			this.list.isFetching = true;
			Toast.info("登录成功");
		}else {
			Tast.info("未知错误");
			this.list.isFetching = false;
		}
	}
}

export default new User();